iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 4
0

操作環境有 GKE 與 kubeadm 自架叢集操作,本篇文章將會帶讀者學會使用 kubectl 觀看集群相關的資訊。

查看預設安裝的 POD 資源

GKE 的環境

$ kubectl get pods -n kube-system # -n 表示 namespace,kube-system 為指定的 namespace
NAME                                                        READY   STATUS    RESTARTS   AGE
event-exporter-v0.3.0-5cd6ccb7f7-mp7p4                      2/2     Running   0          13h
fluentd-gcp-scaler-6855f55bcc-mchvv                         1/1     Running   0          13h
fluentd-gcp-v3.1.1-f8wc8                                    2/2     Running   0          13h
fluentd-gcp-v3.1.1-g6mbn                                    2/2     Running   0          13h
fluentd-gcp-v3.1.1-zq4xm                                    2/2     Running   0          13h
heapster-gke-7c7bdf567c-cmqhm                               3/3     Running   0          13h
kube-dns-5c446b66bd-5ltbw                                   4/4     Running   0          13h
kube-dns-5c446b66bd-fqvwk                                   4/4     Running   0          13h
kube-dns-autoscaler-6b7f784798-hr8ck                        1/1     Running   0          13h
kube-proxy-gke-cluster-1-test-default-pool-255d7fb2-1f8l    1/1     Running   0          13h
kube-proxy-gke-cluster-1-test-default-pool-255d7fb2-lbwc    1/1     Running   0          13h
kube-proxy-gke-cluster-1-test-default-pool-255d7fb2-ppnm    1/1     Running   0          13h
l7-default-backend-84c9fcfbb-kwrrs                          1/1     Running   0          13h
metrics-server-v0.3.3-fdc67d4b6-264zw                       2/2     Running   0          13h
prometheus-to-sd-ktwlz                                      2/2     Running   0          13h
prometheus-to-sd-pfxlh                                      2/2     Running   0          13h
prometheus-to-sd-tvgv7                                      2/2     Running   0          13h
stackdriver-metadata-agent-cluster-level-646c549689-cfftk   2/2     Running   0          13h

以下是預設的 namespace

$ kubectl get namespace # 查看 namespace
NAME              STATUS   AGE
default           Active   13h
kube-node-lease   Active   13h
kube-public       Active   13h
kube-system       Active   13h

雲端介面示意圖

kubeadm 自架叢集,預設 namespace 查看,但在預設的 POD 則是沒 GKE 豐富,需要自行去安裝。

$ kubectl get namespace
NAME              STATUS   AGE
default           Active   4d17h
kube-node-lease   Active   4d17h
kube-public       Active   4d17h
kube-system       Active   4d17h

Kubernetes 版本查看

GKE 環境

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.6", GitCommit:"dff82dc0de47299ab66c83c626e08b245ab19037", GitTreeState:"clean", BuildDate:"2020-07-15T16:58:53Z", GoVersion:"go1.13.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"15+", GitVersion:"v1.15.12-gke.2", GitCommit:"fb7add51f767aae42655d39972210dc1c5dbd4b3", GitTreeState:"clean", BuildDate:"2020-06-01T22:20:10Z", GoVersion:"go1.12.17b4", Compiler:"gc", Platform:"linux/amd64"}

kubeadm 環境

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate:"2020-08-13T16:12:48Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.8", GitCommit:"9f2892aab98fe339f3bd70e3c470144299398ace", GitTreeState:"clean", BuildDate:"2020-08-13T16:04:18Z", GoVersion:"go1.13.15", Compiler:"gc", Platform:"linux/amd64"}

Kubernetes API 資源

GKE 和 kubeadm 原則上會是相同,當中 SHORTNAMES 表示縮寫,可在下指令時用其縮寫表示資源。

$ kubectl api-resources
NAME                              SHORTNAMES   APIGROUP                       NAMESPACED   KIND
bindings                                                                      true         Binding
componentstatuses                 cs                                          false        ComponentStatus
configmaps                        cm                                          true         ConfigMap
endpoints                         ep                                          true         Endpoints
...

Kubernetes Api 版本

GKE 和 kubeadm 原則上會是相同。

$ kubectl api-versions
admissionregistration.k8s.io/v1beta1
apiextensions.k8s.io/v1beta1
apiregistration.k8s.io/v1
apiregistration.k8s.io/v1beta1
...

from zhiweiyin318.github.io

一個 API 對像在 Etcd 裡面完整的資源路徑由:Group(API 組),verison(API 版本)和 Resource(API 資源類型)三個部分組成。

Kubernetes Cluster 資訊

GKE 環境

$ kubectl cluster-info
Kubernetes master is running at https://35.238.20.43
GLBCDefaultBackend is running at https://35.238.20.43/api/v1/namespaces/kube-system/services/default-http-backend:http/proxy
Heapster is running at https://35.238.20.43/api/v1/namespaces/kube-system/services/heapster/proxy
KubeDNS is running at https://35.238.20.43/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
Metrics-server is running at https://35.238.20.43/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

kubeadm 環境

$ kubectl cluster-info
Kubernetes master is running at https://192.168.134.131:6443
KubeDNS is running at https://192.168.134.131:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

結論

今天的內容帶大家操作 Kubernetes 中一些基本資源和叢集資訊的操作,接著下來會進入 POD 的世界。


上一篇
K8s POD 資源基本介紹
下一篇
POD 到底怎樣被控制
系列文
我真的覺得認為 K8s 到底在火什麼30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言